/**
 * // ============================================================================
 * //
 * // Copyright (C) 2006-2007 Dengues
 * //
 * // Google Group: http://groups.google.com/group/dengues
 * // QQ Group: 24885404
 * //
 * // This library is free software; you can redistribute it and/or
 * // modify it under the terms of the GNU Lesser General Public
 * // License as published by the Free Software Foundation; either
 * // version 2.1 of the License.
 * //
 * // This library is distributed in the hope that it will be useful,
 * // but WITHOUT ANY WARRANTY; without even the implied warranty of
 * // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * // Lesser General Public License for more details.
 * //
 * // You should have received a copy of the GNU General Public License
 * // along with this program; if not, write to the Free Software
 * // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * //
 * // ============================================================================
 * 
 *
 * $Id$
 */
package org.dengues.model.project.impl;

import java.util.Collection;
import org.dengues.model.project.CDCConnType;
import org.dengues.model.project.ConnPropertySetType;
import org.dengues.model.project.ProjectPackage;

import org.dengues.model.warehouse.MetadataType;
import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>CDC Conn Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.dengues.model.project.impl.CDCConnTypeImpl#getConnSet <em>Conn Set</em>}</li>
 *   <li>{@link org.dengues.model.project.impl.CDCConnTypeImpl#getSbsTable <em>Sbs Table</em>}</li>
 *   <li>{@link org.dengues.model.project.impl.CDCConnTypeImpl#getCdcTables <em>Cdc Tables</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class CDCConnTypeImpl extends AbstractProjectObjectImpl implements CDCConnType {
    /**
     * The cached value of the '{@link #getConnSet() <em>Conn Set</em>}' reference.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getConnSet()
     * @generated
     * @ordered
     */
    protected ConnPropertySetType connSet;

    /**
     * The default value of the '{@link #getSbsTable() <em>Sbs Table</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getSbsTable()
     * @generated
     * @ordered
     */
    protected static final String SBS_TABLE_EDEFAULT = null;
    /**
     * The cached value of the '{@link #getSbsTable() <em>Sbs Table</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getSbsTable()
     * @generated
     * @ordered
     */
    protected String sbsTable = SBS_TABLE_EDEFAULT;

    /**
     * The cached value of the '{@link #getCdcTables() <em>Cdc Tables</em>}' containment reference list.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getCdcTables()
     * @generated
     * @ordered
     */
    protected EList<MetadataType> cdcTables;

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    protected CDCConnTypeImpl() {
        super();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    protected EClass eStaticClass() {
        return ProjectPackage.Literals.CDC_CONN_TYPE;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public ConnPropertySetType getConnSet() {
        if (connSet != null && connSet.eIsProxy()) {
            InternalEObject oldConnSet = (InternalEObject)connSet;
            connSet = (ConnPropertySetType)eResolveProxy(oldConnSet);
            if (connSet != oldConnSet) {
                if (eNotificationRequired())
                    eNotify(new ENotificationImpl(this, Notification.RESOLVE, ProjectPackage.CDC_CONN_TYPE__CONN_SET, oldConnSet, connSet));
            }
        }
        return connSet;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public ConnPropertySetType basicGetConnSet() {
        return connSet;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain basicSetConnSet(ConnPropertySetType newConnSet, NotificationChain msgs) {
        ConnPropertySetType oldConnSet = connSet;
        connSet = newConnSet;
        if (eNotificationRequired()) {
            ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ProjectPackage.CDC_CONN_TYPE__CONN_SET, oldConnSet, newConnSet);
            if (msgs == null) msgs = notification; else msgs.add(notification);
        }
        return msgs;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setConnSet(ConnPropertySetType newConnSet) {
        if (newConnSet != connSet) {
            NotificationChain msgs = null;
            if (connSet != null)
                msgs = ((InternalEObject)connSet).eInverseRemove(this, ProjectPackage.CONN_PROPERTY_SET_TYPE__CDC_CONN, ConnPropertySetType.class, msgs);
            if (newConnSet != null)
                msgs = ((InternalEObject)newConnSet).eInverseAdd(this, ProjectPackage.CONN_PROPERTY_SET_TYPE__CDC_CONN, ConnPropertySetType.class, msgs);
            msgs = basicSetConnSet(newConnSet, msgs);
            if (msgs != null) msgs.dispatch();
        }
        else if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, ProjectPackage.CDC_CONN_TYPE__CONN_SET, newConnSet, newConnSet));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public String getSbsTable() {
        return sbsTable;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setSbsTable(String newSbsTable) {
        String oldSbsTable = sbsTable;
        sbsTable = newSbsTable;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, ProjectPackage.CDC_CONN_TYPE__SBS_TABLE, oldSbsTable, sbsTable));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public EList<MetadataType> getCdcTables() {
        if (cdcTables == null) {
            cdcTables = new EObjectContainmentEList<MetadataType>(MetadataType.class, this, ProjectPackage.CDC_CONN_TYPE__CDC_TABLES);
        }
        return cdcTables;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case ProjectPackage.CDC_CONN_TYPE__CONN_SET:
                if (connSet != null)
                    msgs = ((InternalEObject)connSet).eInverseRemove(this, ProjectPackage.CONN_PROPERTY_SET_TYPE__CDC_CONN, ConnPropertySetType.class, msgs);
                return basicSetConnSet((ConnPropertySetType)otherEnd, msgs);
        }
        return super.eInverseAdd(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case ProjectPackage.CDC_CONN_TYPE__CONN_SET:
                return basicSetConnSet(null, msgs);
            case ProjectPackage.CDC_CONN_TYPE__CDC_TABLES:
                return ((InternalEList<?>)getCdcTables()).basicRemove(otherEnd, msgs);
        }
        return super.eInverseRemove(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public Object eGet(int featureID, boolean resolve, boolean coreType) {
        switch (featureID) {
            case ProjectPackage.CDC_CONN_TYPE__CONN_SET:
                if (resolve) return getConnSet();
                return basicGetConnSet();
            case ProjectPackage.CDC_CONN_TYPE__SBS_TABLE:
                return getSbsTable();
            case ProjectPackage.CDC_CONN_TYPE__CDC_TABLES:
                return getCdcTables();
        }
        return super.eGet(featureID, resolve, coreType);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @SuppressWarnings("unchecked")
    @Override
    public void eSet(int featureID, Object newValue) {
        switch (featureID) {
            case ProjectPackage.CDC_CONN_TYPE__CONN_SET:
                setConnSet((ConnPropertySetType)newValue);
                return;
            case ProjectPackage.CDC_CONN_TYPE__SBS_TABLE:
                setSbsTable((String)newValue);
                return;
            case ProjectPackage.CDC_CONN_TYPE__CDC_TABLES:
                getCdcTables().clear();
                getCdcTables().addAll((Collection<? extends MetadataType>)newValue);
                return;
        }
        super.eSet(featureID, newValue);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public void eUnset(int featureID) {
        switch (featureID) {
            case ProjectPackage.CDC_CONN_TYPE__CONN_SET:
                setConnSet((ConnPropertySetType)null);
                return;
            case ProjectPackage.CDC_CONN_TYPE__SBS_TABLE:
                setSbsTable(SBS_TABLE_EDEFAULT);
                return;
            case ProjectPackage.CDC_CONN_TYPE__CDC_TABLES:
                getCdcTables().clear();
                return;
        }
        super.eUnset(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public boolean eIsSet(int featureID) {
        switch (featureID) {
            case ProjectPackage.CDC_CONN_TYPE__CONN_SET:
                return connSet != null;
            case ProjectPackage.CDC_CONN_TYPE__SBS_TABLE:
                return SBS_TABLE_EDEFAULT == null ? sbsTable != null : !SBS_TABLE_EDEFAULT.equals(sbsTable);
            case ProjectPackage.CDC_CONN_TYPE__CDC_TABLES:
                return cdcTables != null && !cdcTables.isEmpty();
        }
        return super.eIsSet(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public String toString() {
        if (eIsProxy()) return super.toString();

        StringBuffer result = new StringBuffer(super.toString());
        result.append(" (sbsTable: ");
        result.append(sbsTable);
        result.append(')');
        return result.toString();
    }

} //CDCConnTypeImpl
